<?php

namespace App\Services;

use App\Interfaces\SettingInterface;
use Illuminate\Support\Facades\DB;
use stdClass;

class SettingService implements SettingInterface
{
    /**
     * @param mixed $tenantId
     * @param mixed $field
     * @return stdClass
     */
    public function getConfig(mixed $tenantId, mixed $field)
    {
        $where = array(
            ['tenantId',$tenantId],
            ['field',$field]
        );
        $res = DB::table('setting')->where($where)->get()->first();
        return $res;
    }

    /**
     * 更新数据库中的配置
     * @param array $data
     * @return int
     */
    public function updateConfig(array $data): int
    {
        $where = array(
            ['tenantId',$data['tenantId']],
            ['field',$data['field']]
        );
        $res = DB::table('setting')->where($where)->update($data);
        return $res;
    }
}
